
		set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER TRIGGER [HeadingTemplateCodeOnUpdate] 
   ON  [dbo].[HeadingTemplateCode] 
   AFTER Update
AS 
	declare @tablePrimaryKey int
	declare @UpdateBy nvarchar(50)
	declare @UpdateIP nvarchar(50)
	declare @UpdateDate datetime
	
	select @tablePrimaryKey = [Rowno] from inserted
	select @UpdateBy = [UpdateBy] from inserted
	select @UpdateIP = [UpdateIP] from inserted
	select @UpdateDate = [UpdateDate] from inserted
	

if (update([Rowno]))
 begin
  declare @NewRowno int
  declare @OldRowno int

  select @OldRowno = [Rowno] from Deleted
  select @NewRowno = [Rowno] from inserted
if( @OldRowno != @NewRowno)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('Rowno','HeadingTemplateCode',@tablePrimaryKey,@NewRowno,@OldRowno,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([Section]))
 begin
  declare @NewSection CodeTypeType
  declare @OldSection CodeTypeType

  select @OldSection = [Section] from Deleted
  select @NewSection = [Section] from inserted
if( @OldSection != @NewSection)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('Section','HeadingTemplateCode',@tablePrimaryKey,@NewSection,@OldSection,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([HeadingCode]))
 begin
  declare @NewHeadingCode HeadingCodeType
  declare @OldHeadingCode HeadingCodeType

  select @OldHeadingCode = [HeadingCode] from Deleted
  select @NewHeadingCode = [HeadingCode] from inserted
if( @OldHeadingCode != @NewHeadingCode)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('HeadingCode','HeadingTemplateCode',@tablePrimaryKey,@NewHeadingCode,@OldHeadingCode,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([GroupTypeCode]))
 begin
  declare @NewGroupTypeCode CodeTypeType
  declare @OldGroupTypeCode CodeTypeType

  select @OldGroupTypeCode = [GroupTypeCode] from Deleted
  select @NewGroupTypeCode = [GroupTypeCode] from inserted
if( @OldGroupTypeCode != @NewGroupTypeCode)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('GroupTypeCode','HeadingTemplateCode',@tablePrimaryKey,@NewGroupTypeCode,@OldGroupTypeCode,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([IsDelete]))
 begin
  declare @NewIsDelete int
  declare @OldIsDelete int

  select @OldIsDelete = [IsDelete] from Deleted
  select @NewIsDelete = [IsDelete] from inserted
if( @OldIsDelete != @NewIsDelete)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('IsDelete','HeadingTemplateCode',@tablePrimaryKey,@NewIsDelete,@OldIsDelete,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

